package com.ryenlii.datatrans.code;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * 代码生成工具类
 */
public class CodeGenerator {

    private static String url = "jdbc:TAOS://ip:6030/test?user=root&password=taosdata&timezone=GMT%2b8";
    private static String username = "root";
    private static String password = "taosdata";

    private static String author = "zhengwen";

    private static String output = "C:\\Users\\zhengwen\\Desktop\\test\\code";

    private static String packageName = "com.ryenlii.datatrans";

    private static String moduleName = "";

    private static String tableName = "teacher";

    private static String tablePrefix = "";

    public static void main(String[] args) {

        FastAutoGenerator autoGenerator = FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            // .fileOverride() // 覆盖已生成文件
                            .outputDir(output); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent(packageName) // 设置父包名
                            .moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, output)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tableName) // 设置需要生成的表名
                            .addTablePrefix(tablePrefix); // 设置过滤表前缀
                    //controller策略配置
                    builder.controllerBuilder().enableRestStyle();
                    //service策略配置
                    builder.serviceBuilder().build();
                    //Entity策略配置
                    builder.entityBuilder().enableLombok();
                    //mapper策略配置
                    builder.mapperBuilder().enableBaseResultMap();
                });


        autoGenerator.execute();

    }
}
